using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace WebControl.VehicleSearch
{
    public partial class Vehicle : System.Web.UI.UserControl
    {
        #region PROPERTIES

        public string BranchIdLocationList
        {
            get
            {
                object o = this.ViewState["_BranchIdLocationList"];
                if (o == null)
                    return string.Empty;
                else
                    return (string)o;
            }
            set
            {
                this.ViewState["_BranchIdLocationList"] = value;
            }
        }

        public string CustomizedFilterCode
        {
            get
            {
                object o = this.ViewState["_CustomizedFilterCode"];
                if (o == null)
                    return string.Empty;
                else
                    return (string)o;
            }
            set { this.ViewState["_CustomizedFilterCode"] = value; }
        }

        #endregion

        #region EVENTS

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                LoadData();
            }


            SearchBoxLong1.SearchButtonClicked += new EventHandler(SearchBoxLong1_SearchButtonClicked);
        }

        public void LoadData()
        {
            SelectViewIndex();
            SearchResults1.LoadData();
            SearchBoxLong1.SearchButtonClicked += new EventHandler(SearchBoxLong1_SearchButtonClicked);
        }

        private void SearchBoxLong1_SearchButtonClicked(object sender, EventArgs e)
        {
            SearchResults1.ManufacturerId = SearchBoxLong1.SelectedManufacturerId;
            SearchResults1.ModelId = SearchBoxLong1.SelectedModelId;
            SearchResults1.YearRange = SearchBoxLong1.SelectedYearFrom + "|" + SearchBoxLong1.SelectedYearTo;
            SearchResults1.PriceRange = SearchBoxLong1.SelectedPriceFrom + "|" + SearchBoxLong1.SelectedPriceTo;
            SearchResults1.BranchIdLocationList = BranchIdLocationList;
            SearchResults1.CustomizedFilterCode = CustomizedFilterCode;

            SearchResults1.LoadData();

            VehicleMultiView.ActiveViewIndex = 0;
            //VechicleMultiView.SetActiveView(SearchResultsView);
            SearchBoxLong1.SearchButtonClicked += new EventHandler(SearchBoxLong1_SearchButtonClicked);

            divMessage.InnerHtml = string.Empty;
            if (SearchResults1.Rows <= 0)
            {
                divMessage.InnerHtml = "No records found";
            }
        }

        private void SelectViewIndex()
        {
            if (Request.QueryString["id"] != null && Request.QueryString["id"] != ""
                && Convert.ToInt32(Request.QueryString["id"]) > 0)
            {
                VehicleDetails1.VehicleId = Convert.ToInt64(Request.QueryString["id"]);
                VehicleDetails1.BackUrl = System.IO.Path.GetFileName(this.Parent.Page.Request.PhysicalPath);
                VehicleDetails1.PrinterFriendlyUrl = "/vehicle/vehiclewindowcard.aspx";

                VehicleMultiView.ActiveViewIndex = 1;
                //VechicleMultiView.SetActiveView(VehicleDetailsView);
            }
            else
            {
                VehicleMultiView.ActiveViewIndex = 0;
                //VechicleMultiView.SetActiveView(SearchResultsView);
            }
            SearchBoxLong1.SearchButtonClicked += new EventHandler(SearchBoxLong1_SearchButtonClicked);
        }

        #endregion

    }
}